package com.dom.domweb.modular.controller.sysmger;

import com.dom.common.model.vo.basic.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.ClientInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/base")
public class CustInfoController {

    @Autowired
    private ClientInfoService clientInfoService;

    /**
     * 查询客户信息列表
     * @param limit 每页行数
     * @param page 当前页数
     * @param abbrName 客户简称
     * @param organLicense 营业执照号
     * @return
     */
    @RequestMapping("/getCustInfoList")
    public TabPager getMarketOrderList(@RequestParam("limit")int limit,
                                       @RequestParam("page")int page,
                                       @RequestParam("abbrName")String  abbrName,
                                       @RequestParam("organLicense")String  organLicense
    ) {
        B029R r = new B029R();
        r.setPn(page);
        r.setPs(limit);
        r.setAbbrName(abbrName);
        r.setOrganLicense(organLicense);
        B029A B029A = clientInfoService.findCustInfoList(r);
        return new TabPager(B029A.getCustInfoData(),B029A.getTotalNum());
    }

    /**
     *  查询所有客户信息
     * @return
     */
    @RequestMapping(value="/getAllCustInfo", method = RequestMethod.POST)
    public RspModel getAllCustInfo(){
        List<CustInfo> list = clientInfoService.getAllClientInfo();
        return new RspModel(list);
    }

    /**
     *  新增客户信息
     * @param request 新增客户信息对象
     * @return
     */
    @RequestMapping(value="/insertCustInfo", method = RequestMethod.POST)
    public RspModel insertCustInfo(@RequestBody B020R request){
        RspModel result = clientInfoService.insertCustInfo(request);
        return result;
    }

    /**
     *  查询客户信息明细列表
     * @param id 客户信息id
     * @return
     */
    @RequestMapping(value="/updateCustInfoPage", method = RequestMethod.POST)
    public RspModel findUpdateCustInfoPage(@RequestParam("id")String id){
        B023A result = clientInfoService.findUpdateCustInfoPage(id);
        return new RspModel(result);
    }

    /**
     *  查询客户信息明细列表
     * @param custCode 客户信息id
     * @return
     */
    @RequestMapping(value="/findContInfo", method = RequestMethod.POST)
    public RspModel findContInfo(@RequestParam("custCode")String custCode){
        B023A result = clientInfoService.findContInfo(custCode);
        return new RspModel(result);
    }

    /**
     *  查询客户信息明细列表
     * @param id 客户信息id
     * @return
     */
    @RequestMapping(value="/findContInfoById", method = RequestMethod.POST)
    public RspModel findContInfoById(@RequestParam("id")String id){
        CustLinkInfo result = clientInfoService.findContInfoById(id);
        return new RspModel(result);
    }

    /**
     * 逻辑删除客户信息
     * @param id 客户信息id
     * @return
     */
    @RequestMapping(value = "/custInfoDel",method = RequestMethod.POST)
    public RspModel custInfoDel(@RequestParam("id") String id){
        boolean isTure = clientInfoService.custInfoDel(id);
        RspModel model = new RspModel("RSP000000","客户信息删除成功！");
        if(!isTure){
            model.setRspCode("RSP000001");
            model.setRspMsg("客户信息删除失败！");
        }
        return model;
    }

    @RequestMapping(value = "/custInfoModify", method = RequestMethod.POST)
    public RspModel custInfoModify(@RequestBody B022R request){
        return clientInfoService.custInfoModify(request);
    }
}
